package tests;

import java.util.List;

import junit.framework.Assert;

import org.junit.Test;

import pdi.OpenCvCaller;
import pdi.IO.CSVImgReader;
import pdi.IO.CSVImgWriter;
import pdi.IO.ImgReader;
import pdi.IO.ImgWriter;
import pdi.IO.RawImgReader;
import pdi.IO.RawImgWriter;
import pdi.IO.SeqImgReader;
import pdi.core.Image;
import utils.IConstants;

public class ioTest {

	@Test
	public void testRAWimg(){
		String imgsrc = "./Data/testTrash/read";
		String imgDst = "./Data/testTrash/write";

		ImgReader reader = new RawImgReader(imgsrc);		
		List<Image> imgs = reader.readAll();
		Assert.assertEquals("Not all images were read", imgs.size(), 5);
		
		ImgWriter writer  = new RawImgWriter(imgDst);
		writer.writeAll(imgs);						
	}

	
	@Test
	public void testCSV() {
		String imgsrc = "./Data/testTrash/read/features.csv";
		String imgDst = "./Data/testTrash/write/features.csv";

		ImgReader reader = new CSVImgReader(imgsrc);		
		List<Image> imgs = reader.readAll();
		Assert.assertEquals("Not all images were read", imgs.size(), 5);
		
		ImgWriter writer  = new CSVImgWriter(imgDst);
		writer.writeAll(imgs);	
	}

	@Test
	public void testSeqImg(){
		String dataSetpath = "C:\\Users\\RFSC\\Desktop\\DataSet\\CaltechPedestrianBenchmark\\evaluation_and_labeling_code\\data-INRIA";

		ImgReader reader = new SeqImgReader(dataSetpath);

		List<Image> imgs = reader.readAll();
		Assert.assertEquals("not all images were read", imgs.size(), 1832);

		Image imgt = OpenCvCaller.getInstance().cropImage(imgs.get(0), imgs.get(0).getGroundTruth().get(0).getLeft(), imgs.get(0).getGroundTruth().get(0).getTop(), imgs.get(0).getGroundTruth().get(0).getWidth(), imgs.get(0).getGroundTruth().get(0).getHeight());
		OpenCvCaller.getInstance().showImage(imgt);
		
		int count = 0;
		for (Image img : imgs) {
			if(img.countBB(IConstants.PERSON) == 0)							
				count++;
		}		
		Assert.assertEquals("not all pedestrian annotation were read", count, 1218);

		//ImgWriter writer = new SeqImgWriter()


	}

}
